import qiniuUploader from './qiniuUploader'
let niuUp = (imgArray = []) => {
  if (!Array.isArray(imgArray)) {
    console.error('The parameter type of the niuUp function should be a array.')
    return
  }
  if (imgArray.length === 0) {
    console.error('The parameter type of the niuUp function not be zero.')
    return
  }
  const options = {
    region: 'SCN', // 华北区
    uptokenURL: '****', // 上传地址
    domain: '****', // 配置到七牛云的域名
    shouldUseQiniuFileName: false
  }
  qiniuUploader.init(options)
  let niuniu = (img) => {
    return new Promise((resolve, reject) => {
      qiniuUploader.upload(img, (res) => {
        resolve(res.imageURL)
      }, (error) => {
        resolve('error: ' + JSON.stringify(error))
      }, null, 
        (progress) => {
          console.log('上传进度', progress.progress)
        }
      )
    })
  }
  let upThisImg = imgArray.map((item, index, imgArray) => {
    return niuniu(item)
  })
  return Promise.all(upThisImg)
}
export default niuUp
